package com.fs.service.impl;

import com.fs.entity.Materialcategory;
import com.fs.entity.Materials;
import com.fs.mapper.MaterialallocationMapper;
import com.fs.mapper.MaterialcategoryMapper;
import com.fs.mapper.MaterialsMapper;
import com.fs.service.IMaterialsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fs.util.AutoReview;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-06-12
 */
@Service
public class MaterialsServiceImpl implements IMaterialsService {
    @Autowired
    MaterialsMapper materialsMapper;
    @Autowired
    MaterialcategoryMapper materialcategoryMapper;
    @Autowired
    MaterialallocationMapper materialallocationMapper;
    @Override
    public Boolean handle(Materials material) {
        Boolean res = materialsMapper.insert(material)>0;
        if (materialcategoryMapper.selectByMcId(material.getMcid()).getAutoenable()==1){
            AutoReview.Review(material);
        }
        return res;
    }

    @Override
    public Materials getMaterialDetail(int mid) {
        return materialsMapper.selectById(mid);
    }

    @Override
    public boolean withdrawMaterial(int mid) {
        if (materialallocationMapper.deleteById(mid)>0&&materialsMapper.withdrawMaterial(mid)>0){
            return true;
        }
        return false;
    }
}
